package com.kkb.dao;

import com.kkb.pojo.User;
import com.kkb.util.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDao {
    QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
    public void registerInsert(User user) throws SQLException {
        String sql = "insert into tb_user values(?,?,?,?,?,?,?)";
        Object[] params = {
                user.getId(),user.getUsername(),user.getPassword(),user.getEmail(),
                user.getName(),user.getGender(),user.getBirthday(),
        };
        queryRunner.update(sql,params);
    }

    public User loginQuerry(String username, String password) {
        String sql = "select * from tb_user where username = ? and password = ?";
        Object[] params = {username,password};
        User user = null;
        try {
             user = queryRunner.query(sql, new BeanHandler<User>(User.class), params);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }
}
